import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { STS } from 'ali-oss';
@Injectable()
export class OssService {
  @Inject()
  private configService: ConfigService;
  async getStsTokenForOssUpload() {
    const sts = new STS({
      accessKeyId: this.configService.get('accesskey_id'),
      accessKeySecret: this.configService.get('accesskey_secret'),
    });
    const res = await sts.assumeRole(
      this.configService.get('ali_oss_roleArn'),
      '',
      3000,
      'asuka_oss',
    );
    return {
      AccessKeyId: res.credentials.AccessKeyId,
      AccessKeySecret: res.credentials.AccessKeySecret,
      SecurityToken: res.credentials.SecurityToken,
    };
  }
}
